
//引入请求封装
import {
    request
} from "../../request/request.js"; 
Page({

    /**
     * 页面的初始数据
     */
    data: {
        // 图片路径
        img: '/image/',
        // 人数显示
        show: true,
        user: []
    },
    Data:{
        taskId:''
    },
    Data2:{
        joinId:'',
        taskId:'',
        pushOpenId:'',
    },
    // 点击完成任务
    complete() {
        let that = this
        wx.showModal({
            title: "是否确定已完成任务,确认后将会支付给对应参与者相应赏金",
            success(res) {
                if (res.confirm) {
                    that.completeTask()
                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            },
            fail() {
                return
            }
        })
    },
    async completeTask(){
        let that = this
        const res = await request({
            url: "/completeTask",
            data: this.Data2,
            method: "get"
        })
        console.log(res)
        that.getInfor()
    },

    // 获取用户完成情况
    async getInfor(){
        let that = this
        const res = await request({
            url: "/getCompleteInfor",
            data: this.Data,
            method: "get"
        })
        console.log(res)
        that.Data2.joinId = res.data[0].user._id
        this.setData({
            user:res.data
        })

    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (e) {
        let that = this
        console.log(e)
        this.setData({
            num : e.num
        })
        this.Data.taskId = e.id
        this.Data2.taskId = e.id
        wx.getStorage({
            key: 'token',
            success(res) {
                that.Data2.pushOpenId = res.data
            },
        })
        this.getInfor()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})